import { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import react from '@vitejs/plugin-react'

export default defineConfig({
  main: {
    plugins: [externalizeDepsPlugin()],
    build: {
      lib: {
        entry: resolve('main/index.ts'),
      },
      // 新增输出目录配置
      outDir: 'out/main'
    }
  },
  preload: {
    plugins: [externalizeDepsPlugin()],
    build: {
      lib: {
        entry: resolve('preload/index.ts'),
      },
      outDir: 'out/preload'
    }
  },
  renderer: {
    root: resolve('renderer'),
    // 关键修复：添加基础路径
    base: './',
    build: {
      outDir: 'out/renderer',
      emptyOutDir: true,
      rollupOptions: {
        input: {
          index: resolve('renderer/index.html'),
        },
        // 确保静态资源正确处理
        output: {
          assetFileNames: 'assets/[name].[hash].[ext]'
        }
      }
    },
    resolve: {
      alias: {
        '@renderer': resolve('renderer/src')
      }
    },
    plugins: [react()],
  }
})
